﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
using Manager.App_Code;
using Manager.App_Code.DAL;
using Manager.Common;

namespace Manager.FormAdd_Edit
{
    public partial class frm_BackupDatabase : DevExpress.XtraEditors.XtraForm
    {
        NewPearl_HotelDataContext db = new NewPearl_HotelDataContext();

        public frm_BackupDatabase()
        {
            InitializeComponent();
        }

        QuanTriHeThongDAL func = new QuanTriHeThongDAL();
        private void btninput_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog openfolderdlg = new FolderBrowserDialog();
            string resultdlg;
            if (openfolderdlg.ShowDialog() == DialogResult.OK)
            {
                resultdlg = openfolderdlg.SelectedPath; ;
                txtpath.Text = resultdlg.ToString();
            }
        }

        private void btnbackup_Click(object sender, EventArgs e)
        {
            try
            {
                string path = txtpath.Text + "\\" + "backup_" + DateTime.Now.ToString("ddMMyyyy") + ".bak";
                db.ExecuteCommand("BACKUP DATABASE NewPearl_Hotel TO DISK = '" + path + "'  WITH  FORMAT");
                MessageBox.Show("Backup thành công.");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Không backup được.");
                Log.WriteLog(ex.StackTrace);
            }
            //String temp = "";
            //temp = txtpath.Text + "\\" + "backup_" + DateTime.Now.ToString("ddMMyyyy") + ".bak";
            //SqlParameter[] param1 = { new SqlParameter("@PathFile", temp) };
            //try
            //{
            //    func.call_procedure_P_noreturn("fullbackup", param1);
            //    MessageBox.Show("Backup thành công");
            //}
            //catch
            //{
            //    MessageBox.Show("Backup thất bại");
            //}
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}